<?php (!defined('IN_SYSTEM') || !defined('ADMIN_PRE')) && exit('Access Denied!');?>
{admintemplate header}
<div class="box">
	<div class="heading">
	<h1>撰写文章</h1>
	<div class="buttons">
	{if ican('artindex')}
	<a href="{url admin.php?m=article}">文章列表</a>
	{/if}
	{if ican('artwrite')}
	<a href="{url admin.php?m=article&f=write}" >撰写文章</a>
	{/if}
	{if ican('catindex')}
	<a href="{url admin.php?m=category}" >文章类别</a>
	{/if}
	</div>
	</div>
	<div class="main">	
	<form name="save" method="post" action="{url admin.php?m=article&f=save}" onsubmit="return check_write()" autocomplete="off">
	<input type="hidden" name="savetype" value="{$article['savetype']}" />
	<input type="hidden" name="todraft" id="todraft" value="0" />
	<input type="hidden" name="gourl" id="gourl" value="{$_G['gourl']}" />
	<input type="hidden" name="aid" value="{$article['aid']}" />
		<table class="sub">
			<tr>
				<td width="40">标题：</td>
				<td><input type="text" name="title" id="title" class="input" size="70" value="{$article['title']}" onfocus="if(this.value=='未命名文章')this.value=''" /></td>
			</tr>
			<tr>
				<td width="40">别名：</td>
				<td><input type="text" name="urlname" id="urlname" class="input" size="70" value="{$article['urlname']}" onblur="check_urlname()" /> <input type="checkbox" onclick="getalias(this)"/>自动获取    <span id="tip_urlname">显示在url上的日志名称</span></td>
			</tr>
			<tr>
				<td>分类：</td>
				<td>
				<select name="cid">
					<option value="0">请选择类别</option>
					{get_category_options($article['cid'])}
				</select>
				类型：
				<select name="status">
				{get_status_options($article['status'])}
				</select>
				</td>
			</tr>
			<tr>
				<td>属性：</td>
				<td valign="top">
				{if ican('artpromote')}
				<input type="checkbox" name="istop" value="1" id="istop"  class="checkbox" {if $article['istop']}checked="checked"{/if} /><label for="istop">置顶文章</label>
				<input type="checkbox" name="iscommend" value="1" id="iscommend"  class="checkbox" {if $article['iscommend']}checked="checked"{/if} /><label for="iscommend">推荐文章</label>
				{/if}
				<input type="checkbox" name="needpsw" value="1" id="needpsw"  class="checkbox"  onclick="$('#span_psw').toggle()" {if !empty($article['password'])}checked="checked"{/if}/><label for="needpsw">日志密码</label>
				<span id="span_psw" {if empty($article['password'])}style="display:none;"{/if}>
				<input type="text" name="password" value="{$article['password']}" size="15" class="input" />
				</span>
				<input type="radio" name="timetype" value="0" class="radio" id="t0" checked="checked" onclick="$('#ctime').hide()"/><label for="t0">当前时间</label>
				<input type="radio" name="timetype" value="1" class="radio" id="t1" onclick="$('#ctime').show()"/><label for="t1">自定义时间</label>
				<span id="ctime" style="display:none;">
				<input type="text" size="20" name="timestr" value="{$article['dateline']}" />
				</span>
				</td>
			</tr>
			<tr>
				<td>标签：</td>
				<td><input type="text" class="input" name="tags" id="tags" size="50" value="{$article['tags']}" /> <input type="checkbox" name="showtags" value="1" onclick="$('#hot_tags').toggle()" id="showtags" class="checkbox" /><label for="showtags">显示常用标签</label> <span>多个标签用空格分隔</span></td>
			</tr>
			<tbody id="hot_tags" style="display:none;">
			<tr>
			<td></td><td>
				<dl id="utags">
					<dd>{get_hot_tags()}</dd>
				</dl>
			</td></tr>
			</tbody>
			<tr>
				<td>来源：</td>
				<td valign="top">
				<input type="text" name="fromsite" value="{$article['fromsite']}" size="10" class="input" />
				地址：
				<input type="text" name="fromurl" value="{$article['fromurl']}" size="40" class="input" />
				</td>
			</tr>
			<tr>
				<td valign="top">摘要：</td>
				<td><textarea name="excerpt" rows="3" cols="75">{$article['summary']}</textarea></td>
			</tr>
			<tr>
				<td style="vertical-align:top">上传：<input type="hidden" id="default_image" name="default_image" value="0"></td>
				<td><iframe src="{url index.php?m=upload&t=$type}" width="100%" style="height:30px;" id="uploadframe"  frameborder="0" scrolling="auto" ></iframe></td>
			</tr>
			{if !empty($attachments) || !empty($exattachments)}
			<tr>
				<td>附件：</td>
				<td><input type="checkbox" name="show_attachments" value="1" onclick="$('#attachments').toggle()" id="show_attachments" class="checkbox" checked="checked" /><label for="show_attachments">显示该文章下的附件</label></td>
			</tr>
			<tbody id="attachments">
			<tr>
				<td></td>
				<td>
				<table width="98%" cellspacing="1">
					<tr>
						<th>文件名</th>
						<th width="80">文件大小</th>
						<th width="120">上传时间</th>
						<th width="100">操作</th>
					</tr>
					{loop $attachments $attach}
					<tr id="tr_{$attach['fid']}" onmouseover="this.className='bg2'" onmouseout="this.className=''">
						<td>
						<?php
						if ( stristr($attach['filetype'], 'image') ) {
							$src = $attach['filepath'];
							$preview ='<div class="preview" id="attach_'.$attach['fid'].'"><img src="'.DATA_DIR.'files/'.$src.'" class="thumb" /></div>';
							$insert = '[img]'.$src.'[/img]';
							if(!empty($attach['thumb']))$insert_thumb = '[img]'.$attach['thumb'].'[/img]';
						} else {
							$preview = '';
							$insert = '[file]'.$src.'[/file]';
						}
						$s='<img src='.DATA_DIR.'files/'.$src.'>';
						if($insert_thumb)echo '[<a href="javascript:;" onclick="insert_attach(\''.$insert_thumb.'\')">插入缩略图</a>] ';
						echo '[<a href="javascript:;" onclick="insert_attach( \''.$insert.'\')">插入</a>] &nbsp; [<a href="javascript:;" onclick="insert_attach(\''.$s.'\')">可视化插入</a>] &nbsp;&nbsp;<a href="'.DATA_DIR.'files/'.$src.'" target="_blank" class="attach">'.$attach['originalname'].$preview.'</a>';
						if($article['default_image'] && $attach['thumb'] == $article['default_image']) echo ' [<a href="javascript:;" onclick="del_front(\''.$article['aid'].'\')">取消封面图片</a>]';
						?>
						</td>
						<td width="80">{sizecount($attach['filesize'])}</td>
						<td width="120">{gdate('Y-m-d H:i',$attach['dateline'])}</td>
						<td width="50"><a href="javascript:;" onclick="del_attach({$attach['fid']})">删除</a> &nbsp;&nbsp; <a href="javascript:;" onclick="to_front({$attach['fid']},{$article['aid']})">设为封面</a> </td>
					</tr>
					{/loop}
					<?php if(!empty($exattachments)){?>
					<tr><td colspan="4">以下图片未使用</td></tr>
					<?php }?>
					<?php
					foreach ( $exattachments as $attach ) : 
					?>
					<tr id="tr_<?php echo $attach['fid']?>" onmouseover="this.className='bg2'" onmouseout="this.className=''">
						<td>
						<?php
						if ( stristr($attach['filetype'], 'image') ) {
							$src =$attach['filepath'];
							$preview ='<div class="preview" id="attach_'.$attach['fid'].'"><img src="'.DATA_DIR.'files/'.$src.'" class="thumb" /></div>';
							$insert = '[img]'.$src.'[/img]';
							if(!empty($attach['thumb']))$insert_thumb = '[img]'.$attach['thumb'].'[/img]';
						} else {
							$preview = '';
							$insert = '[file]'.$attach['filepath'].'[/file]';
						}
						$s='<img src='.DATA_DIR.'files/'.$src.'>';
						if($insert_thumb)echo '[<a href="javascript:;" onclick="insert_attach( \''.$insert_thumb.'\')">插入缩略图</a>] ';
						echo '[<a href="javascript:;" onclick="insert_attach( \''.$insert.'\')">插入</a>]&nbsp; [<a href="javascript:;" onclick="insert_attach(\''.$s.'\')">可视化插入</a>] &nbsp;&nbsp;<a href="javascript:;" class="attach" onmouseover="$(\'#attach_'.$attach['fid'].'\').show();" onmouseout="$(\'#attach_'.$attach['fid'].'\').hide();">'.$attach['originalname'].$preview.'</a>';
						if($article['default_image'] && $attach['thumb'] == $article['default_image']) echo ' [<a href="javascript:;" onclick="del_front(\''.$article['aid'].'\')">取消封面图片</a>]';
						?>
						</td>
						<td width="80"><?php echo sizecount($attach['filesize'])?></td>
						<td width="120"><?php echo gdate('Y-m-d H:i',$attach['dateline'])?></td>
						<td width="50"><a href="javascript:;" onclick="del_attach(<?php echo $attach['fid']?>)">删除</a> &nbsp;&nbsp; <a href="javascript:;" onclick="to_front(<?php echo $attach['fid']?>,<?php echo $article['aid']?>)">设为封面</a> </td>
					</tr>
					<?php endforeach;?>
				</table>
				</td>
			</tr>
			</tbody>
			{/if}
			<tr>
				<td valign="top">内容：</td><td><?php echo editor('content','content',$article['content'].'','default','100%','350px',true)?></td>
			</tr>
			<tr>
			<td></td><td>
				<input type="submit" class="button" value="保存文章" />
				<input type="button" class="button" value="另存为草稿" onclick="save_to_draft()" />
				<input type="button" class="button" value="返回上一页" onclick="history.back()" />
			</td>
			</tr>
		</table>
	</form>
	<script type="text/javascript">set_tags_on();</script>

	</div>
</div>
<?php include(ADMIN_ROOT.'template/footer.tpl.php');?>